package sample.androidwidget.view;

import android.content.Context;
import android.gesture.GestureOverlayView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by zhangming on 16/7/7.
 */
public class GestureOverlay extends GestureOverlayView {

    private boolean usefulGesture = true;//判断手势是否有效,无效时不会触发OnGesturePerformedListener事件

    public GestureOverlay(Context context) {
        this(context, null);
    }

    public GestureOverlay(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GestureOverlay(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public boolean isUsefulGesture() {
        return usefulGesture;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                usefulGesture = isGesturing();
                break;
            default:
                usefulGesture = true;
                break;
        }
        return super.dispatchTouchEvent(event);
    }
}
